package view.room;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.BevelBorder;

public class RoomContent extends JPanel{
	private static final long serialVersionUID = 1L;
	RoomTable roomTable;
	RoomInfo  roomInfo;
	
	public RoomContent(){
		setLayout(new BorderLayout());
		
	
		add(roomTable = new RoomTable());
		add(roomInfo = new RoomInfo(), BorderLayout.SOUTH);
	}
	
	class RoomTable extends JPanel{
		int row_count = 10;
		int col_count = 11;
		
		int room_count = 110;
		JButton[] btRoom;
		
		public RoomTable(){
			setLayout(new BorderLayout());
			JPanel jpanel = new JPanel();
			jpanel.setLayout(new GridLayout(row_count, col_count , 15, 15));
			jpanel.setPreferredSize(new Dimension(95*col_count, 95*row_count));
			btRoom = new JButton[room_count];
			
			for (int i=0; i<room_count; i++){
				btRoom[i] = new RoomButton("ROOM " + (i+1));
				btRoom[i].addActionListener(new RoomSelectListener(i));
				jpanel.add(btRoom[i]);
			}
			for (int i=0; i<row_count*col_count-room_count; i++){
				jpanel.add(new JLabel());
			}
			JScrollPane scroll = new JScrollPane(jpanel); 
			add(scroll);
		}
		
		class RoomButton extends JButton{
			public RoomButton(String title){
				super(title);
				setPreferredSize(new Dimension(80, 80));
			}
		}
	}
	
	public void filter(int type, int status){
		roomInfo.updateRoom(-1);
	}
	
	class RoomSelectListener implements ActionListener{
		int roomId;
		public RoomSelectListener(int index){
			roomId = index;
		}
		public void actionPerformed(ActionEvent event){
			roomInfo.updateRoom(roomId);
		}
	}
}
